<template>
    <div>
        <h1>科室修改</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">科室名称</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>

                <tr>
                    <td align="right">科室人数</td>
                    <td><input type="text" v-model="info.ProPel"></td>
                </tr>

                <tr>
                    <td align="right">科室描述</td>
                    <td><textarea v-model="info.MiaoShu"></textarea></td>
                </tr>

                <tr>
                    <td align="right">创建日期</td>
                    <td><input type="date" v-model="info.ConTime"></td>
                </tr>

                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="修改" @click="ok"></td>
                </tr>

            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let info: any = reactive({
    Id: route.query.id,
    Name: '',
    ProPel: '',
    MiaoShu: '',
    ConTime: '',
})
onMounted(() => {
    getFind();
})
const ok = () => {
    axios({
        url: '/api/KS/KSUpdate',
        method: 'put',
        data: info
    })
        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert("科室名称");
                return;
            }
            if (res.data > 0) {
                alert("修改成功");
                router.push('/ksshow');
                return;
            }
            else {
                alert("修改失败");
                return;
            }
        })
        .catch((err) => {
            console.log(err);

        })
}
//===================================反填
const getFind = () => {
    axios({
        url: '/api/KS/KSFind',
        method: 'get',
        params: {
            id: route.query.id
        }
    })
        .then((res) => {
            console.log(res);
            Object.assign(info, res.data)
            info.ConTime = res.data.ConTime.substring(0, 10);

        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped></style>